<?php

	//getting values from the request
	$usrnm = $_GET['usrnm'];
	
	//mysql_connect(url , username , password)
	//url : host of the database
	//username : username of the database
	//password : password of the database
	
	$con = mysql_connect("localhost","user1789586","adobephotoshopcs5");
	if(!$con)
		//if connection fails then it will be considered as warning and remaining
		//script will be executed expect the sql part
		die("could not connect ".mysql_error());

  
	//selecting the database
	mysql_select_db("db1789586-main",$con);
	
	//create table if not exist
	
	$query = 'CREATE TABLE IF NOT EXISTS usrdetails 
	(
	usrnm varchar(150) PRIMARY KEY,
	pswd varchar(32),
	fname varchar(50),
	lname varchar(50),
	sex varchar(1),
	dob varchar(10)
	)';
	
	$result = mysql_query($query);
	
	
	//writing mysql query to fetch a username
	$query = 'Select * FROM usrdetails WHERE usrnm="'.$usrnm.'"';
	//executing the query
	$result = mysql_query($query);
	
	$count = 0;
	
	//the while loop will run till all the row are parsed
	//if there are multiple results
	while($row = mysql_fetch_array($result)){
		$count++;
	}
	
	if($count == 0)
		$arr = array('result'=>'Available');
	else
		$arr = array('result'=>'Unavailable');
	
	echo json_encode($arr);
?>